<?php
namespace Api\Controller;

use Think\Controller;

class SystemController extends SuperController
{

    public function System()
    {
        $systemInfo = M("system");
        $rs_systemInfo = $systemInfo->where("sId=1")->find();
        $this->ajaxSucReturn($rs_systemInfo);
    }

    //系统设置提交
    public function SystemAction()
    {
        $post = I('post.');
        if(!$post['sCheckCodeSwitch']){
            $this->ajaxErrReturn("验证码开关必须设置");
        }
        if(!$post['sCompany']){
            $this->ajaxErrReturn("公司名称必须");
        }
        if(!$post['sCompanyTel']){
            $this->ajaxErrReturn("公司电话必须");
        }
        $data["sName"] = $post["sName"];
        $data["sUrl"] = $post["sUrl"] ? : '';
        $data["sCompany"] = $post["sCompany"] ? : '';
        $data["sCompanyTel"] = $post["sCompanyTel"] ? : '';
        $data["sCompanyIntroduce"] = $post["sCompanyIntroduce"] ? : '';
        $data["sDepartment"] = $post["sDepartment"] ? : '';
        $data["order_contral"] = $post["order_contral"] ? : '1,2,3,4,5,6,7';
        if ($data["sDepartment"] == "") {
            $data["sDepartment"] = "部门";
        }
        $data["sCheckCodeSwitch"] = $post["sCheckCodeSwitch"] ? : '';
        $data["sErrorPwdLockNum"] = $post["sErrorPwdLockNum"] ? : '';
        $data["sLoginTimeout"] = $post["sLoginTimeout"] ? : '';
        $data["sCopyrightName"] = $post["sCopyrightName"] ? : '';
        if ($data["sCopyrightName"] == "") {
            $data["sCopyrightName"] = "云南爱之情信息科技有限公司";
        }
        $data["sCopyrightAuthor"] = $post["sCopyrightAuthor"];
        if ($data["sCopyrightAuthor"] == "") {
            $data["sCopyrightAuthor"] = "阮金波";
        }
        $data["sCopyrightAuthorTel"] = $post["sCopyrightAuthorTel"];
        if ($data["sCopyrightAuthorTel"] == "") {
            $data["sCopyrightAuthorTel"] = "15887835880";
        }
        $data["sCopyrightAuthorQQ"] = $post["sCopyrightAuthorQQ"];
        if ($data["sCopyrightAuthorQQ"] == "") {
            $data["sCopyrightAuthorQQ"] = "309091579";
        }
        /*
        $sLogo = $_FILES["sLogo"];
        if (strlen($sLogo["name"]) > 0) {
            $upload = new \Think\Upload(); // 实例化上传类
            $upload->maxSize = 3145728; // 设置附件上传大小
            $upload->exts = array(
                'jpg',
                'gif',
                'png',
                'jpeg'
            ); // 设置附件上传类型
            $rootPath = $upload->rootPath = './'; // 设置附件上传根目录
            $upload->savePath = 'Uploads/Logo/'; // 设置附件上传（子）目录
            $upload->subName = array(
                'date',
                'Ymd'
            );
            // 上传文件
            $info = $upload->upload();
            if (! $info) { // 上传错误提示错误信息
                $this->error($upload->getError());
            }
            foreach ($info as $file) {
                $imgsUrl = $file['savepath'] . $file['savename'];
            }
            $data["sLogo"] = $imgsUrl;
        }
        */
        $data["sLogo"] = I('sLogo') ? : '';
        $systemSet = M("system");
        $result = $systemSet->where("sId=1")->save($data);
        if ($result) {
            $this->ajaxSucReturn("更新成功");
        } else {
            $this->ajaxErrReturn("更新失败");
        }
    }

    //设置
    public function set() {
       $set = M("set");
       $rs = $set->where("setId=1")->find();
       $this->ajaxSucReturn($rs);
    }

    public function setAction(){
        $set = M("set");
        $data["setDayMoney"]=$_POST["setDayMoney"];
        $data["setWorkingUseTime"]=$_POST["setWorkingUseTime"];
        $data["setLongWorkMoney"]=$_POST["setLongWorkMoney"];
        $data["setDayHour"]=$_POST["setDayHour"];
        $data["setFullDayMoney"]=$_POST["setFullDayMoney"];
        $data["setFullDayAlgorithm"]=$_POST["setFullDayAlgorithm"];
        $result=$set->where("setId=1")->save($data);
        if ($result) {
            $this->ajaxSucReturn("更新成功");
        } else {
            $this->ajaxErrReturn("更新失败");
        }
    }
}